package com.huike.report.mapper;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;

import com.huike.clues.domain.vo.IndexStatisticsVo;
import org.apache.ibatis.annotations.Select;

/**
 * 首页统计分析的Mapper
 * @author Administrator
 *
 */
public interface ReportMapper {
	/**=========================================基本数据========================================*/
	/**
	 * 获取线索数量
	 * @param beginCreateTime	开始时间
	 * @param endCreateTime		结束时间
	 * @param username			用户名
	 * @return
	 */
	Integer getCluesNum(@Param("startTime") String beginCreateTime,
						@Param("endTime") String endCreateTime,
						@Param("username") String username);

	/**
	 * 获取商机数量
	 * @param beginCreateTime	开始时间
	 * @param endCreateTime		结束时间
	 * @param username			用户名
	 * @return
	 */
	Integer getBusinessNum(@Param("startTime") String beginCreateTime,
						   @Param("endTime") String endCreateTime,
						   @Param("username") String username);

	/**
	 * 获取合同数量
	 * @param beginCreateTime	开始时间
	 * @param endCreateTime		结束时间
	 * @param username			用户名
	 * @return
	 */
	Integer getContractNum(@Param("startTime") String beginCreateTime,
						   @Param("endTime") String endCreateTime,
						   @Param("username") String username);

	/**
	 * 获取合同金额
	 * @param beginCreateTime	开始时间
	 * @param endCreateTime		结束时间
	 * @param username			用户名
	 * @return
	 */
	Double getSalesAmount(@Param("startTime") String beginCreateTime,
						  @Param("endTime") String endCreateTime,
						  @Param("username") String username);

	/**
	 * 查询所有的线索总数
	 * @return
	 * @param begin
	 * @param end
	 */
	@Select("select count(0) from tb_clue where create_time between #{begin} and #{end}")
    Integer count(@Param("begin") LocalDate begin,@Param("end") LocalDate end);

	/**
	 * 查询有效溴铵所的数量
	 * @return
	 * @param begin
	 * @param end
	 */
	@Select("select count(0) from tb_clue where status in ('1','2','5','6','7') and create_time between #{begin} and #{end}")
	Integer effectiveCluesNums(@Param("begin") LocalDate begin,@Param("end") LocalDate end);

	@Select("select count(0) from tb_business where create_time between #{begin} and #{end}")
	Integer businessNums(@Param("begin") LocalDate begin,@Param("end") LocalDate end);

	@Select("select count(0) from tb_contract where create_time between #{begin} and #{end}")
	Integer contractNums(@Param("begin") LocalDate begin,@Param("end") LocalDate end);

	@Select("select count(id) from tb_business where create_time between #{begin} and #{end}")
	Integer businessCount(@Param("begin") LocalDateTime begin,@Param("end") LocalDateTime end);

	@MapKey("id")
	List<Map<String, Object>> contractStatistics(@Param("begin") LocalDateTime begin,@Param("end") LocalDateTime end);

	Integer clueCount(@Param("begin") LocalDateTime begin,@Param("end") LocalDateTime end);

	@MapKey("id")
	List<Map<String, Object>> salesStatistic(@Param("begin") LocalDateTime begin,@Param("end") LocalDateTime end);


	/**=========================================今日简报========================================*/



	/**=========================================待办========================================*/

}
